package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.linlinjava.litemall.db.dao.CustomHerbMapper;
import org.linlinjava.litemall.db.dao.LitemallHerbMapper;
import org.linlinjava.litemall.db.domain.LitemallHerb;
import org.linlinjava.litemall.db.domain.LitemallHerbExample;
import org.springframework.stereotype.Service;

@Service
public class CustomHerbService {
    @Resource
    private CustomHerbMapper customHerbMapper;
    @Resource
    private LitemallHerbMapper herbMapper;

    public List<Map> getHerbGenerics(String query,String orderByClause) {
        return customHerbMapper.selectHerbGenerics(query, orderByClause);
    }

    public List<Map> getHerbGenericsDescribe(String query,String orderByClause) {
        return customHerbMapper.selectHerbGenericsDescribe(query, orderByClause);
    }

    public LitemallHerb query(Integer userId, Integer id) {
    	LitemallHerbExample example = new LitemallHerbExample();
        example.or().andIdEqualTo(id).andUserIdEqualTo(userId).andDeletedEqualTo(false);
        return herbMapper.selectOneByExample(example);
    }

    public int add(LitemallHerb herb) {
    	herb.setAddTime(LocalDateTime.now());
    	herb.setUpdateTime(LocalDateTime.now());
        return herbMapper.insertSelective(herb);
    }

    public int update(LitemallHerb herb) {
    	herb.setUpdateTime(LocalDateTime.now());
        return herbMapper.updateByPrimaryKeySelective(herb);
    }
    
}
